﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Web;
using OGS.Contracts;
using OGS.DataAccess;
using OGS.Utility;

namespace OGS.Web.Models.Admin
{
    public class SaveUOMModel
    {
        /// <summary>
        /// The ID
        /// </summary>
        public int ID
        {
            get;
            set;
        }

        /// <summary>
        /// The Name
        /// </summary>
        [Display(Name = "Unit Of Measurement")]
        [Required(ErrorMessage = "Please enter unit of measurement.")]
        public string Name
        {
            get;
            set;
        }

        /// <summary>
        /// Checks whether the UOM Is Active
        /// </summary>
        [Display(Name = "Is Active")]
        public bool IsActive
        {
            get;
            set;
        }

        public bool IsSuccess { get; set; }

        /// <summary>
        /// Get UOM Details
        /// </summary>
        /// <param name="ID"></param>
        /// <returns></returns>
        public void GetUOMDetails(int ID)
        {
            UOM oUOM = DAUOM.Instance.GetUOMDetails(ID);
            this.ID = oUOM.ID;
            this.Name = oUOM.Name;
            this.IsActive = oUOM.IsActive;
        }

        /// <summary>
        /// Save UOM
        /// </summary>
        public int SaveUOM()
        {
            UOM oUOM = new UOM();
            oUOM.ID = this.ID;
            oUOM.Name = this.Name;
            oUOM.IsActive = this.IsActive;
            oUOM.LastModifiedBy = Helper.GetCurrentUserID();
            oUOM.LastModifiedDate = DateTime.Now;

            int result = DAUOM.Instance.SaveUOM(oUOM);
            this.ID = oUOM.ID;
            return result;
        }
    }
}